#include "ServerStatus.hpp"
#include <stdexcept>

ServerStatus::ServerStatus(std::string url)
  : client(url)
{
}

bool ServerStatus::GetTerminalConnect()
{
  auto res=client.Get("/Terminal/ConnectStatus");
  if(res==nullptr)
    return false;
  if(res->body=="1")
    return true;
  else
    return false;
}

bool ServerStatus::GetRecordStatus()
{
  auto res=client.Get("/Camera/Record/Status");
  if(res==nullptr)
    return false;
  if(res->body=="1")
    return true;
  else
    return false;
}

void ServerStatus::StartMonitor()
{
  auto res=client.Get("/Camera/Monitor/Start");
  if(res==nullptr)
    throw std::runtime_error("无法启动相机进入预览模式");
  if(res->status!=200)
    throw std::runtime_error("无法启动相机进入预览模式");
}
